<?php
/*
 * 车型库汽车批发类
 * @package    auto
 * @author     Wl
 * @copyright  Copyright (c) 2013 ixdcw team
 * @version    $Id: 2469766570bea192bcb94a8c98423d97b88dfd51 $
 */

defined('IN_IXDCW') or exit('Access Denied');

class AutoInsuranceModule extends BasicModule {

	/** @var 条目ID */
	private $_itemid;

	/** @var string 表格 */
	private $_table;

	/** @var  数据库前缀 */
	private $_pre;


	function __construct() {
		parent::__construct();
		$this->_pre = $this->_db->getPre();
		$this->_table = Table::name(Table::NAME_AUTO_INSURANCE);
		$this->_fields     = array('arbid','arcid','amid','catid','mycatid','areaid','typeid','level','title','tag','style','fee','introduce','model','standard','brand','unit','price','minamount','amount','days','thumb','thumb1','thumb2','tag','status','hits','username','totime','editor','addtime','adddate','edittime',
			'editdate','ip','template','linkurl','filepath','elite','note','company','truename','telephone','mobile','address','email','msn','qq','ali','skype');
    }

	public function setItemid($itemid) {
		$this->_itemid = $itemid;
	}

	public function getItemid() {
		return $this->_itemid;
	}

	public function getFields() {
		return $this->_fields;
	}

	/**
	 * 检测用户传值
	 * @param $post
	 * @return bool 检测是否通过测试
	 */
	function pass($post) {
		if(!is_array($post)) return false;
		if(!$post['contact_name']) return $this->err('请输入姓名');
		if(!$post['contact_telephone']) return $this->err('请输入联系方式');
		if(!$post['contact_address']) return $this->err('请输入地址');
		if(!$post['model_name']) return $this->err('请输入车款');
		if(!$post['buy_time']) return $this->err('请输入购车时间');
		if(!$post['close_time']) return $this->err('请输入车险到期时间');
		if(!$post['clrar_preferential']) return $this->err('请输入已知优惠');
		if(!$post['quotation_company']) return $this->err('请输入报价单位');
		return true;
	}


	/**
	 * 获取一条数据
	 * @return array|void
	 */
	function getOne() {
		return  $this->_db->getOne("SELECT * FROM {$this->_table} WHERE id=$this->_itemid");
	}

	/**
	 * 获取列表
	 * @param string $condition
	 * @param string $order
	 * @param string $cache
	 * @return array
	 */
	function getList($condition = '1=1', $order = 'edittime DESC', $table='',  $cache = '') {
		global $items;
		if(!$table) $table = Table::name(Table::NAME_AUTO_INSURANCE);
		$num = $this->_db->count($table, $condition, $cache);
		$items=$num;
		$this->_pn->recordsPerPage($this->_pagesize);
		$this->_pn->records($num);
		$sql = "SELECT * FROM {$table}";
		$sql .= $condition ? " WHERE {$condition}" : '';
		$sql .= $order ? " ORDER BY {$order}" : '';
		$sql .= " LIMIT " . ($this->_pn->getPage() - 1) * $this->_pagesize . ',' . $this->_pagesize;
		$lists = $catids = $CATS = array();
		$result = $this->_db->query($sql, $cache);
		while($r = $this->_db->fetchArray($result)) {
			$lists[] = $r;
		}
		return $lists;
	}


}
?>
